#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include <string>

TEST(allocs, freelist) {
  EXPECT_TRUE(true);
}

class DbInterfase
{
  public:
  DbInterfase(){}
  virtual int GetTime() = 0;//{return 0;};
  virtual bool Connect(std::string) = 0;//{return true;};
};

class DataBase : public DbInterfase
{
  public:
  DataBase() = default;

  int GetTime() override { return 3;};
  bool Connect(std::string) override{ return true;};
};

class MockDb : public DbInterfase
{
  public:
  MockDb() = default;
  MOCK_METHOD(int, GetTime, (), (override));
  MOCK_METHOD(bool, Connect, (std::string), (override));
};

class SomeApp
{
  public:
  SomeApp(DbInterfase &db): db_{db}{}

  bool StartApp()
  {
    return db_.Connect("asdasd");
  }
  
  private:
  DbInterfase &db_;
};


TEST(Mocks, test_mock) {

  // Arrange
  MockDb db;
  SomeApp app(db);

  // Act

  EXPECT_CALL(db, Connect("T1"))
                                .Times(1)
                                .WillOnce(testing::Return(false))
                                .WillRepeatedly(testing::Return(true));
  //  .WillOnce(WillRepeatedly(false));              // Can be used at most once

  // Assert
  EXPECT_TRUE(app.StartApp());
}